# !/usr/bin/python
# -*- coding: UTF-8 -*-

import threading
import time
import httpclient
import config
import car

exitFlag = 0


class myThread(threading.Thread):  # 继承父类threading.Thread
    def __init__(self, threadID, name, list, des):
        threading.Thread.__init__(self)
        self.threadID = threadID
        self.name = name
        self.list = list
        self.des = des

    def run(self):  # 把要执行的代码写到run函数里面 线程在创建后会直接运行run函数
        print_time(self.name, self.list, self.des)


def print_time(threadName, list, des):
    car.findCarDesc(list)


for x in range(100000):
    start = x * 1000
    data = {'start': start, 'carStatus': 1, 'type': 0}
    carList = httpclient.sendJson(data, config.getConfig("url", "findCar"))
    size = len(carList)
    ki = divmod(size, 3)
    sizeList = ki[0]
    yushu = ki[1]
    list1 = carList[0:sizeList]
    list2 = carList[sizeList:sizeList + sizeList]
    list3 = carList[sizeList + sizeList:sizeList + sizeList + sizeList + yushu]
    # 创建新线程
    thread1 = myThread(1, "Thread-1", list1, 4)
    thread2 = myThread(2, "Thread-2", list2, 2)
    thread3 = myThread(3, "Thread-3", list3, 1)
    # 开启线程
    thread1.start()
    thread2.start()
    thread3.start()
    if len(carList) < 1000:
        break

    break
